var mongoose = require('mongoose');
require('../model/comment.model');
var commentModel = mongoose.model('Comment');

module.exports={
    addComment:addComment,
    findByMerchantId:findByMerchantId,
    findByOrderId:findByOrderId
};

function addComment(commentInfo,callBack){
    commentModel.create(commentInfo,function (err,doc) {
        callBack(err,doc);
    });
}


function findByMerchantId(merchantId,callBack){
    commentModel.find({merchant:merchantId},function(err,doc){
        callBack(err,doc);
    }).sort({createTime:-1});
}


function findByOrderId(orderId,callBack){
    commentModel.findOne({order:orderId},function(err,doc){
        callBack(err,doc);
    });
}




